#pragma once

#include<iostream>
#include<pthread.h>
#include<ctime>
#include<string>

typedef void (*callback_t)();

static int num=1;  
class Thread
{
public:
    static void* Rount(void* args)
    {
        Thread* thread=static_cast<Thread*>(args);
        thread->Entry();

        return nullptr;
    }
public:
    Thread(callback_t cb)
    :tid(0),name(""),
    start_timestamp(0),isrunning_(false),
    cb_(cb)
    {}
    void Run()
    {
        std::string name="thread+"+std::to_string(num++);
        start_timestamp=time(nullptr);
        isrunning_=true;
        pthread_create(&tid,nullptr,Rount,this);
    }

    void join()
    {
        pthread_join(tid,nullptr);
        isrunning_=false;
    }
    std::string Name()
    {
        return name;
    }
    uint64_t StartTimestamp()
    {
        return start_timestamp;
    }
    bool IsRunning()
    {
        return isrunning_;
    }
    void Entry()
    {
        cb_();
    }

private:
    pthread_t tid;
    std::string name;
    uint64_t start_timestamp;
    bool isrunning_;

    callback_t cb_;
};